package com.leileimann.tour.controller.AdminPages;

import com.leileimann.tour.common.ResultMapUtil;
import com.leileimann.tour.entity.Admin;
import com.leileimann.tour.entity.SSpot;
import com.leileimann.tour.mapper.AdminMapper;
import com.leileimann.tour.mapper.SSpotMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author leileiMann
 * @date 2022/3/27 21:07
 */
@RestController
@RequestMapping("/admin")
public class AdminContorller {
    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private SSpotMapper sSpotMapper;

    /**管理员登陆方法*/
    @RequestMapping("/toALogin")
    @ResponseBody
    public Object toALogin(HttpSession session, @Param("tel")String tel, @Param("password")String password){
        //先进行输入的值判断是否为空
        if (tel == null || password == null){
            return ResultMapUtil.getHashMapLogin("手机号码和密码不能为空!","2");
        }
        Admin admin = adminMapper.adminLogin(tel, password);
        if (admin != null){
            if (admin.getTel().equals(tel)&&admin.getPassword().equals(password)){
                //管理员登录成功将管理员信息放入session中
                session.setAttribute("admin",admin);
                System.out.println("admin的信息为："+admin);
                return ResultMapUtil.getHashMapLogin("登录成功！正在进入系统","1");
            }else{
                return ResultMapUtil.getHashMapLogin("号码或密码输入错误！","2");
            }
        }else{
            return ResultMapUtil.getHashMapLogin("号码或密码输入错误！","2");
        }
    }

//    景区管理使用

    /**显示所有景区*/
//    @RequestMapping("/getAllSSpot")
//    @ResponseBody
    public List<SSpot> getAllSSpot(int pagenum){
        return sSpotMapper.getAllSSpot(pagenum);
    }

}
